/**
 * Copyright (C), 2020-2021 by colley.ma
 * File Name: FutureTimeFilter.java
 * Encoding: UTF-8
 * Date: 2021年4月2日 下午2:10:43
 * History:
*/
package com.swak.frame.api.filter.spi;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.swak.frame.chain.FilterInvoker;
import com.swak.frame.common.SpringBeanFactory;
import com.swak.frame.context.BoundContext;
import com.swak.frame.extension.adapter.FutureClockTime;
import com.swak.frame.filter.ApiFilter;
import com.swak.frame.filter.FilterConstants;
import com.swak.frame.system.SystemConfigurable;

/**
 * 穿越时间设置, 依赖接口的直接 RpcParamRequest中获取 获取直接FutureTimeClock.getDate(pin) 获取
 * ClassName: FutureClockTimeFilter.java
 * 
 * @author colley.ma
 * @date 2021年4月2日 下午3:07:34
 */
public class FutureClockTimeFilter implements ApiFilter {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	private FutureClockTime futureClockTime = SpringBeanFactory.getBean(FutureClockTime.class);

	private SystemConfigurable systemConfig = SpringBeanFactory.getBean(SystemConfigurable.class);;

	@Override
	public void doFilter(BoundContext context, FilterInvoker<BoundContext> nextFilter) {
		if (systemConfig.getBoolean(FilterConstants.FUTURE_CLOCK, true)) {
			logger.info("start doFilter:{}", DateTime.now().toString());
			// 设置穿越时间
			context.getRequest().setFutureTime(futureClockTime.getClockTime(context.getRequest().getPin()));
		}
		// 下一个流程
		nextFilter.invoke(context);
	}
}
